home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / UUCICO / ULIBNT.C < prev    next >
C/C++ Source or Header  |  1993-10-03  |  29KB  |  840 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u l i b n t . c                                                 */
  3. /*                                                                    */
  4. /*    Windows NT serial port support for UUCICO                       */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) David M. Watt 1993, All Rights Reserved   */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  13. /*    Wonderworks.                                                    */
  14. /*                                                                    */
  15. /*    All rights reserved except those explicitly granted by the      */
  16. /*    UUPC/extended license agreement.                                */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*--------------------------------------------------------------------*/
  20. /*                          RCS Information                           */
  21. /*--------------------------------------------------------------------*/
  22.  
  23. /*
  24.  *       $Id: ulibnt.c 1.6 1993/10/03 22:09:09 ahd Exp $
  25.  *       $Log: ulibnt.c $
  26.  * Revision 1.6  1993/10/03  22:09:09  ahd
  27.  * Use unsigned long to display speed
  28.  *
  29.  * Revision 1.5  1993/09/26  03:32:27  dmwatt
  30.  * Use Standard Windows NT error message module
  31.  *
  32.  * Revision 1.4  1993/09/25  03:07:56  ahd
  33.  * Add standard Windows NT error message calls
  34.  *
  35.  * Revision 1.3  1993/09/21  01:42:13  ahd
  36.  * Use standard MAXPACK limit for save buffer size
  37.  *
  38.  * Revision 1.2  1993/09/20  04:50:57  ahd
  39.  * Break out of ULIBOS2.C
  40.  *
  41.  * Revision 1.14  1993/05/30  15:25:50  ahd
  42.  * Multiple driver support
  43.  *
  44.  * Revision 1.13  1993/05/30  00:08:03  ahd
  45.  * Multiple communications driver support
  46.  * Delete trace functions
  47.  *
  48.  * Revision 1.12  1993/05/09  03:41:47  ahd
  49.  * Make swrite accept constant input strings
  50.  *
  51.  * Revision 1.11  1993/04/11  00:34:11  ahd
  52.  * Global edits for year, TEXT, etc.
  53.  *
  54.  * Revision 1.10  1993/04/10  21:25:16  dmwatt
  55.  * Add Windows NT support
  56.  *
  57.  * Revision 1.9  1993/04/05  04:32:19  ahd
  58.  * Additional traps for modem dropping out
  59.  *
  60.  * Revision 1.8  1993/04/04  04:57:01  ahd
  61.  * Add configurable OS/2 priority values
  62.  *
  63.  * Revision 1.7  1992/12/30  13:02:55  dmwatt
  64.  * Dual path for Windows NT and OS/2
  65.  *
  66.  * Revision 1.6  1992/12/11  12:45:11  ahd
  67.  * Correct RTS handshake
  68.  *
  69.  * Revision 1.5  1992/12/04  01:00:27  ahd
  70.  * Add copyright message, reblock other comments
  71.  *
  72.  * Revision 1.4  1992/11/29  22:09:10  ahd
  73.  * Add new define for BC++ OS/2 build
  74.  *
  75.  * Revision 1.3  1992/11/19  03:00:39  ahd
  76.  * drop rcsid
  77.  *
  78.  * Revision 1.2  1992/11/15  20:11:48  ahd
  79.  * Add English display of modem status and error bits
  80.  *
  81.  */
  82.  
  83. /*--------------------------------------------------------------------*/
  84. /*                        System include files                        */
  85. /*--------------------------------------------------------------------*/
  86.  
  87. #include <stdlib.h>
  88. #include <stdio.h>
  89. #include <string.h>
  90. #include <fcntl.h>
  91. #include <io.h>
  92. #include <time.h>
  93.  
  94. /*--------------------------------------------------------------------*/
  95. /*                      Windows NT include files                      */
  96. /*--------------------------------------------------------------------*/
  97.  
  98. #include <windows.h>
  99. #include <limits.h>
  100.  
  101. /*--------------------------------------------------------------------*/
  102. /*                    UUPC/extended include files                     */
  103. /*--------------------------------------------------------------------*/
  104.  
  105. #include "lib.h"
  106. #include "ulib.h"
  107. #include "ssleep.h"
  108. #include "catcher.h"
  109.  
  110. #include "commlib.h"
  111. #include "pnterr.h"
  112.  
  113. /*--------------------------------------------------------------------*/
  114. /*                          Global variables                          */
  115. /*--------------------------------------------------------------------*/
  116.  
  117. currentfile();
  118.  
  119. static boolean   carrierdetect = FALSE;  /* Modem is not connected     */
  120.  
  121. static boolean hangupNeeded = FALSE;
  122. static boolean console = FALSE;
  123.  
  124. static currentSpeed = 0;
  125.  
  126. #define FAR_NULL ((PVOID) 0L)
  127.  
  128. /*--------------------------------------------------------------------*/
  129. /*           Definitions of control structures for DOS API            */
  130. /*--------------------------------------------------------------------*/
  131.  
  132. static HANDLE hCom;
  133. static COMMTIMEOUTS CommTimeout;
  134. static DCB dcb;
  135.  
  136. static BYTE com_status;
  137. static USHORT com_error;
  138.  
  139. static USHORT usPrevPriority;
  140.  
  141. static void ShowError( const USHORT status );
  142.  
  143. static void ShowModem( const DWORD status );
  144.  
  145. /*--------------------------------------------------------------------*/
  146. /*    n o p e n l i n e                                               */
  147. /*                                                                    */
  148. /*    Open the serial port for I/O                                    */
  149. /*--------------------------------------------------------------------*/
  150.  
  151. int nopenline(char *name, BPS baud, const boolean direct )
  152. {
  153.    DWORD dwError;
  154.    BOOL rc;
  155.  
  156.    if (portActive)              /* Was the port already active?     ahd   */
  157.       closeline();               /* Yes --> Shutdown it before open  ahd   */
  158.  
  159. #ifdef UDEBUG
  160.    printmsg(15, "nopenline: %s, %lu",
  161.                  name,
  162.                  (unsigned long) baud);
  163. #endif
  164.  
  165. /*--------------------------------------------------------------------*/
  166. /*                      Validate the port format                      */
  167. /*--------------------------------------------------------------------*/
  168.  
  169.    if (!equal(name,"CON") && !equaln(name, "COM", 3 ))
  170.    {
  171.       printmsg(0,"nopenline: Communications port begin with COM, was %s",
  172.          name);
  173.       panic();
  174.    }
  175.  
  176. /*--------------------------------------------------------------------*/
  177. /*                          Perform the open                          */
  178. /*--------------------------------------------------------------------*/
  179.  
  180.    hCom = CreateFile( name,
  181.         GENERIC_READ | GENERIC_WRITE,
  182.         0,
  183.         NULL,
  184.         OPEN_EXISTING,
  185.         0,
  186.         NULL);
  187.  
  188. /*--------------------------------------------------------------------*/
  189. /*    Check the open worked.  We translation the common obvious       */
  190. /*    error of file in use to english, for all other errors are we    */
  191. /*    report the raw error code.                                      */
  192. /*--------------------------------------------------------------------*/
  193.  
  194.    if (hCom == INVALID_HANDLE_VALUE) {
  195.        dwError = GetLastError();
  196.        printmsg(0, "nopenline: OpenFile error on port %s", name);
  197.        printNTerror("nopenline", dwError);
  198.        return TRUE;
  199.    }
  200.  
  201. /*--------------------------------------------------------------------*/
  202. /*                    Check for special test mode                     */
  203. /*--------------------------------------------------------------------*/
  204.  
  205.    if ( equal(name,"CON"))
  206.    {
  207.       portActive = TRUE;     /* record status for error handler        */
  208.       carrierdetect = FALSE;  /* Modem is not connected                 */
  209.       console = TRUE;
  210.       return 0;
  211.    }
  212.  
  213.    console = FALSE;
  214.  
  215. /*--------------------------------------------------------------------*/
  216. /*            Reset any errors on the communications port             */
  217. /*--------------------------------------------------------------------*/
  218.  
  219.    rc = ClearCommError (hCom,
  220.         &dwError,
  221.         NULL);
  222.  
  223.    if (!rc) {
  224.       printmsg(0, "nopenline: Error in ClearCommError() call\n");
  225.       printNTerror("nopenline", dwError);
  226.    }
  227.  
  228. /*--------------------------------------------------------------------*/
  229. /*                           Set baud rate                            */
  230. /*--------------------------------------------------------------------*/
  231.  
  232.